package com.example.administrator.q1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class listActivity extends AppCompatActivity {

    ListView listView_one;
    List<String> myList = new ArrayList<String>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);

        listView_one = (ListView)findViewById(R.id.listView_one);
        // init myList
        for (int i = 0; i < 6; i++) {
            myList.add("Oh, My dear " + i + " Sir!"+" nice to meet you hear!!!");
        }

        // context：上下文->当前的，正在运行的。。。
        MyAdapter myAdapter = new MyAdapter(listActivity.this, myList);
        if (myAdapter != null)
            listView_one.setAdapter(myAdapter);
        else {
            Toast.makeText(listActivity.this, "对不起，因为。。。而崩溃了", Toast.LENGTH_SHORT).show();
        }
    }


}
